# -*- coding: utf-8 -*-

# __date:       2021/6/10
# __author:     YangChao
# __function:

import time
from core.instrument.SA4051C import SA4051C


class SpectrumAnalyzer:

    def __init__(self):
        self.VNA = None
        # self.VNA = SA4051C()

    def config_default(self, RF:float, LO:float, SB:float):
        """
        初始化频率分析仪
        :param lo: 本振频率
        :param rf: RF频率
        :param sb: 边带频率
        :return:
        """
        # 将三个频点标记上
        self.VNA.set_marker(1, 'Pos', position=RF)
        self.VNA.set_marker(2, 'Pos', position=LO)
        self.VNA.set_marker(3, 'Pos', position=SB)

    def set_center(self, freq: float):
        # 设置中心频率
        self.VNA.set_center(freq)

    def local_leak(self):
        # 获取本振泄露
        time.sleep(0.5)
        p_rf = self.VNA.get_marker(1)
        p_lo = self.VNA.get_marker(2)
        return p_rf - p_lo

    def sideband_leak(self):
        # 获取边带泄露
        time.sleep(0.5)
        p_rf = self.VNA.get_marker(1)
        p_sb = self.VNA.get_marker(3)
        return p_rf - p_sb

    def get_power(self, marker: int):
        # 获取指定频点的功率
        return self.VNA.get_marker(marker)